<%@ page language="java" import="java.util.*,java.util.Map" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="com.ncp.model.entity.cart.CartBean"%>
<jsp:useBean id="cart" scope="session" class="com.ncp.model.biz.cart.ShoppingCart"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>购物车</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="css/cart.css">
	
	<script src="js/cart/cart.js" type="text/javascript"></script>
	
	<%
	out.clear();
	int buynum = 1;
	String action = (String)request.getParameter("action");
	String productID = (String)request.getParameter("pid");
	if("".equals(request.getParameter("buynum"))||null==request.getParameter("buynum")){
		buynum = 1;
	}else{
		buynum = Integer.parseInt((String)request.getParameter("buynum"));
	}
	System.out.println("buynum="+buynum);
	System.out.println(action);
	System.out.println(productID);
	if("add".equals(action)){
		cart.addProduct(productID,buynum);
		//out.print("<script language=javascript>refreshHead();</script>");
	}
	else if("del".equals(action)){
		cart.delProduct(productID);
		//out.print("<script language=javascript>refreshHead();</script>");
	}
	else if("empty".equals(action)){
		cart.clearCart();
		//out.print("<script language=javascript>refreshHead();</script>");
	}
    %>
  </head>
  
  <body>
    <h2>购物车详细</h2>
    <table class="default">
    	<tr>
    		<td width="35%" class="item">产品名称</td>
    		<td width="25%" class="item">价格</td>
    		<td width="15%" class="item">数量</td>
    		<td width="15%" class="item">小记</td>
    		<td width="15%" class="item">删除</td>
    	</tr>
    	<%
    		if(cart.getProductNum()!=0){
    			Map<String,CartBean> cartMap = null;
    			cartMap = cart.getCartMap();
    			CartBean cartBean = null;
    			Iterator<String> hmkey = cartMap.keySet().iterator();
    			while(hmkey.hasNext()){
    				cartBean = cartMap.get(hmkey.next());
    				%>
    					<tr>
			    			<td align="center"><%=cartBean.getProductName() %></td>
			    			<td align="center"><%=cartBean.getRetailPrice() %></td>
			    			<td align="center"><%=cartBean.getProductNumOfCart() %></td>
			    			<td align="center" style="color:read"><%=(cartBean.getRetailPrice() * cartBean.getProductNumOfCart())%> 元</td>
			    			<td><input type="button" onclick="delProduct('<%=cartBean.getProductID()%>')" value="删除"></td>
    					</tr>
    				<%
    			}
    	 	%>
    	 	<tr style="font-weight:bold">
    	 		<td>总计</td>
    			<td></td>
    			<td align="center"><%=cart.getProductNum()%></td>
    			<td align="center"><%=cart.getTotalprice() %></td>
    			<td></td>
    	 	</tr>
    	 	<tr>
    	 		<td colspan="5" style="text-align:right"><input type="button" value="清空购物车" onclick="emptyCart()"/></td>
    	 	</tr>
    	 	<tr>
    	 		<form name="pay_now_form" action="HandleCartServlet" method="post">
    	 			<td colspan="5" style="text-align:right"><input type="submit" name="pay_now" value="结算" /></td>
    	 		</form>
    	 	</tr>
    	 	<%
    	 	}else{
    	 		%>
    	 			<tr><td colspan="5" style="hight:50px" align="center">您还没有选择任何产品</td></tr>
    	 		<%
    	 	}
    	  %>
    </table>
  </body>
</html>
